const { orderInfo, orderDetail } = require("../../../utils/api");

// pages/orderdetail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetail: {},
    orderId: '',
    showSure: false

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      orderId: options.orderid
    })
    this.getOrder()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  copyId() {
    let that = this
    wx.setClipboardData({
      data: that.data.orderDetail.id,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail(err) {

      }
    })
  },
  //查看物流信息
  toLogistic(e) {

    wx.navigateTo({
      url: `/pages/logisticsinfo/index?orderid=${e.currentTarget.dataset.item.id}`,
    })
  },


  async getOrder() {
    let params = {
      orderid: this.data.orderId
    }
    await orderInfo(params).then((res) => {

      if (res.errcode == 0) {
        this.setData({
          orderDetail: res.data.order
        })
      } else {
        wx.showToast({
          title: res.errmsg,
          icon: 'none',
        });

      }
    })
  },

  onBack() {
    wx.navigateBack({
      delta: 1
    })
  },

  changeAgain() {
    wx.reLaunch({
      url: `/packageA/pages/goodsdetail/index?goodsid=${this.data.orderDetail.goods.id}`,
    })
  },

  confirmGoods() {
    this.setData({
      goodsId: this.data.orderDetail.id,
      showSure: true
    })
  },
  //补件


  toBujian(e) {

    wx.navigateToMiniProgram({
      appId: 'wxcd2b42bc52a3935f',
      path: e.currentTarget.dataset.item.goods.inputurl,
      success(res) {

      }
    })
  },
})